package com.example.dlx4.service;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * ClassName:MessageService
 * Package:com.example.dlx4.service
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/8/13-13:41
 * @Version:v1.0
 */
@Service
@Slf4j
public class MessageService {

    @Value("${my.exchangeNormalName}")
    private String exchangeNormalName;

    @Value("${my.queueNormalName}")
    private String queueNormalName;

    @Value("${my.exchangeDlxName}")
    private String exchangeDlxName;

    @Value("${my.queueDlxName}")
    private String queueDlxName;

    @Resource
    private RabbitTemplate rabbitTemplate;

    private static final String Message = "测试队列最大长度";

    public void sendMsg() {


        org.springframework.amqp.core.Message message = MessageBuilder.withBody(Message.getBytes()).build();

        rabbitTemplate.convertAndSend(exchangeNormalName, "order", message);


        log.info("消息发送完毕,发送时间为:{}", new Date());
    }
}
